package com.jjty.dataGenerator.sxhcampus.utils;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.alibaba.excel.metadata.data.ReadCellData;
import com.jjty.dataGenerator.sxhcampus.service.SxHCampusService;
import com.jjty.dataGenerator.sxhcampus.vo.ActiveImportData;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class ActiveDataImportReadListener extends AnalysisEventListener<ActiveImportData> {
    List<ActiveImportData> list = new ArrayList<>();

    private SxHCampusService service;

    private String fileName;

    private String agentId;

    public ActiveDataImportReadListener(SxHCampusService service,String fileName,String agentId) {
        this.service = service;
        this.fileName = fileName;
        this.agentId = agentId;
    }

    public ActiveDataImportReadListener() {
        super();
    }


    @Override
    public void invokeHead(Map<Integer, ReadCellData<?>> headMap, AnalysisContext context) {
        super.invokeHead(headMap, context);
    }

    @Override
    public void invokeHeadMap(Map<Integer, String> headMap, AnalysisContext context) {
        super.invokeHeadMap(headMap, context);
    }

    @Override
    public void invoke(ActiveImportData data, AnalysisContext context) {
        list.add(data);
    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext context) {
        try {
            service.afterExcelAnalyse(list,fileName,agentId);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
    }

}
